package test;

//: initialization/TerminationCondition.java
// Using finalize() to detect an object that
// hasn't been properly cleaned up.

class Book {
	boolean checkedOut = false;

	Book(boolean checkOut) {
		checkedOut = checkOut;
	}

	void checkIn() {
		checkedOut = false;
	}

	protected void finalize() {
		if (checkedOut)
			System.out.println("Error: checked out");
		else {
			System.out.println("Ok: checked in");
		}
		// Normally, you'll also do this:
		// super.finalize(); // Call the base-class version
	}
}

public class TerminationCondition {
	public static void main(String[] args) {
		for (int i = 0; i < 10; ++i)
			new Book(false);
		for (int i = 0; i < 10; ++i)
			new Book(true);
		System.gc();
	}
} /*
 * Output: Error: checked out
 */// :~
